package main

import (
	"git.mycaigou.com/gfyx/micro-gfyx-user-service/infrastructure/common/utils"
	"git.mycaigou.com/gfyx/micro-gfyx-user-service/infrastructure/common/xxljob"
	"git.mycaigou.com/gfyx/micro-gfyx-user-service/infrastructure/startup"
	"git.mycaigou.com/ycg/stark-extend/starkcommon"
	"git.myscrm.cn/golang/common/ykenv"
	"git.myscrm.cn/golang/stark/v4"
	"git.myscrm.cn/golang/stark/v4/app"
	"log"
)

// 此处定义当前服务的名字
const APP_NAME = "micro-gfyx-user-service"

func main() {
	if ykenv.IsDevMode() {
		utils.TestTool()
	}

	runner, err := app.NewRunner(&stark.Application{
		Name:       APP_NAME,
		Type:       stark.APP_TYPE_GRPC,
		LoadConfig: startup.LoadConfig,
		SetupVars:  startup.SetupVars,
	})
	if err != nil {
		log.Fatalf("app.NewRunner err: %v", err)
	}

	if !ykenv.IsDevMode() {
		xxljob.InitExecutor()
	}

	err = runner.ListenGRPCServer(&stark.GRPCApplication{
		RegisterGRPCServer:      startup.RegisterGRPCServer,
		RegisterGateway:         startup.RegisterGateway,
		RegisterHttpRoute:       nil,
		UnaryServerInterceptors: startup.RegisterMiddleware(),
		TrackLogger:             starkcommon.RegisterTrackLogger(),
		PanicLogger:             starkcommon.RegisterPanicLogger(),
	})

	if err != nil {
		log.Fatalf("runer.ListenGRPCServer err: %v", err)
	}
}
